package com.example.demo.controller;
import com.example.demo.model.Users;
import com.example.demo.service.IUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator 张喜英
 */

    @Api(tags = "users")
    @RestController
    @RequestMapping("/swagger4")
    public class UsersController {
        @Autowired
        private IUsersService usersService;
    @CrossOrigin
    @ApiOperation(value="对用户信息的添加方法")
    @PostMapping("/insertusers")
    public int insertUsers(@RequestBody Users users){
        System.out.println("进入添加用户接口" );
        return usersService.insertUsers(users);
    }

    @PostMapping("/getAll")
    public List<Users> getAllUsers(@RequestBody Users users)
    {
        System.out.println("进入查询方法");
        List<Users> listUsers=usersService.getAllUsers(users);
        return listUsers;
    }
    @PostMapping("/editUsers")
    public int EditUsers(@RequestBody Users users){
        System.out.println("添加修改方法");
        return usersService.updateUsers(users);
}
    @GetMapping("/delUsers")
    public int Delete(int yhid){
        System.out.println("进入删除方法");
        int returnValues=0;
        if(yhid!=0){
            Users users=new Users();
            users.setYhid(yhid);
        returnValues=usersService.deleteUsers(users);
        }
        return returnValues;
    }

    @GetMapping("/getOne")
    public Users getUsers(int yhid){
        Users users=new Users();
        System.out.println("进入单条查询方法");
        if(yhid!=0){
            Users users1=new Users();
            users1.setYhid(yhid);
            users=usersService.getUsers(users1);
            System.out.println("返回的数据集合为:"+users.getYhid());
        }
        return users;
    }








}
